-
Notifications
You must be signed in to change notification settings - Fork 7.1k
simplify dispatcher if-elif #7084
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This works at runtime and with JIT, but Lines 120 to 122 in 035d99f
it treats all annotations with vision/torchvision/prototype/transforms/functional/_misc.py Lines 158 to 160 in 035d99f
for vision/torchvision/prototype/transforms/functional/_misc.py Lines 184 to 185 in 035d99f
I'm not sure how this worked before, since in any case due to our JIT annotation, neither I see three ways forward here:
My preference is 3. -> 2. -> 1. |
Thanks for looking into it Philip. I agree with the order of preference and I'm happy with 3. |
@@ -46,7 +46,7 @@ class ToImageTensor(Transform): | |||
def _transform( | |||
self, inpt: Union[torch.Tensor, PIL.Image.Image, np.ndarray], params: Dict[str, Any] | |||
) -> datapoints.Image: | |||
return F.to_image_tensor(inpt) # type: ignore[no-any-return] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Due to the relaxed strictness, this one (and the ones below) became obsolete.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot Philip, LGTM.
I have 2 follow-up questions / comments, which we can address (or not) in other PRs:
-
As discussed offline, JIT "isn't supported" for the datapoints on these dispatchers. What we mean by "not supported" is that the datapoints will be treated as a pure Tensors, and the output will be a Tensor too. I assume this can lead to unexpected results and confusion, e.g.:
mask = Mask(...) out = T(mask) # - unaware user expects a Mask but gets a Tensor # - `T` treats mask as an image, not as a mask! # Might result in different behaviour (very bad) or confusing error message?
so: should we fail loudly with a good error message in the disaptchers when
is_scripting()
is True andis_simple_tensor()
is False? -
Side note: should we be more lenient with
mypy
checks in the prototype area?
We introduced strict checks in make mypy more strict for prototype datasets #4513 (and I approved the PR, so I'll concede I'm sort of rebutting myself here).
But the the prototype area is where we want to be able to move fast, and try potentially crazy things without having to worry too much about type checks / docs / super clean tests. In this specific case, the introduction ofwarn_return_any
could have been the reason for these convoluted checks in the first place which complicates the code and slows down iteration speed. Perhaps we may want to relax the mypy requirements in order to experiment faster in the prototype area?
|
|
Reviewed By: YosuaMichael Differential Revision: D42706906 fbshipit-source-id: 7f9db8942b704e35054fb842e806dd016db127a2
Fixes #7082 (comment).
cc @vfdev-5 @datumbox @bjuncek